package com.guofen.controller.sjq;

import com.guofen.pojo.SjqFlocculationCraftScene;
import com.guofen.pojo.SjqFlocculationProduceFault;
import com.guofen.service.sjq.SjqFlocculationProduceFaultService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/flocculationProduceFault")
@Controller
@Api(tags = "SjqFlocculationProduceFaultController", description = "絮凝生产现场记录表(故障记录)")
public class SjqFlocculationProduceFaultController {

    @Autowired
    private SjqFlocculationProduceFaultService sjqFlocculationProduceFaultService;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name = "equipmentName", value = "设备名称", required = true) @RequestParam String equipmentName,
                          @ApiParam(name = "Downtime", value = "故障停机时间", required = true) @RequestParam String Downtime,
                          @ApiParam(name = "operate_person", value = "操作人", required = true) @RequestParam String operate_person,
                          @ApiParam(name = "fault_description", value = "故障情况描述", required = true) @RequestParam String fault_description,
                          @ApiParam(name = "start_time", value = "维修开始时间", required = true) @RequestParam String start_time,
                          @ApiParam(name = "end_time", value = "维修结束时间", required = true) @RequestParam String end_time,
                          @ApiParam(name = "personIncharge", value = "维修负责人", required = true) @RequestParam String personIncharge,
                          @ApiParam(name = "repair_person", value = "维修人员名字", required = true) @RequestParam String repair_person,
                          @ApiParam(name = "fault_analysis", value = "故障原因分析", required = true) @RequestParam String fault_analysis,
                          @ApiParam(name = "repair_method", value = "维修方法", required = true) @RequestParam String repair_method,
                          @ApiParam(name = "method_person", value = "提出人", required = true) @RequestParam String method_person,
                          @ApiParam(name = "recovery_time", value = "故障恢复时间", required = true) @RequestParam String recovery_time,
                          @ApiParam(name = "check_person", value = "检查人", required = true) @RequestParam String check_person){
        if (sjqFlocculationProduceFaultService.addForm(equipmentName, Downtime, operate_person, fault_description, start_time, end_time,
                personIncharge, repair_person, fault_analysis, repair_method, method_person, recovery_time, check_person))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查找所有故障设备名称")
    @RequestMapping(value = "/findFaultEquipList",method = RequestMethod.GET)
    @ResponseBody
    public Result findFaultEquipList() {
        return  ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.findFaultEquipList());
    }

    @ApiOperation("查询最新一条记录")
    @RequestMapping(value = "/findForm", method = RequestMethod.GET)
    @ResponseBody
    public Result findForm(){
        if (sjqFlocculationProduceFaultService.findForm() != null)
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="equipmentname",value="设备名称",required=true) @RequestParam String equipmentname,
                         @ApiParam(name="downtime",value="故障停机时间",required=true) @RequestParam String downtime,
                         @ApiParam(name="operatePerson",value="操作人",required=true) @RequestParam String operatePerson,
                         @ApiParam(name="faultDescription",value="故障情况描述",required=true) @RequestParam String faultDescription,
                         @ApiParam(name="startTime",value="维修起始时间",required=true) @RequestParam String startTime,
                         @ApiParam(name="endTime",value="维修终止时间",required=true) @RequestParam String endTime,
                         @ApiParam(name="personincharge",value="维修负责人",required=true) @RequestParam String personincharge,
                         @ApiParam(name="repairPerson",value="维修人员名字",required=true) @RequestParam String repairPerson,
                         @ApiParam(name="faultAnalysis",value="故障原因分析",required=true) @RequestParam String faultAnalysis,
                         @ApiParam(name="repairMethod",value="维修方法",required=true) @RequestParam String repairMethod,
                         @ApiParam(name="methodPerson",value="维修方法提出人",required=true) @RequestParam String methodPerson,
                         @ApiParam(name="recoveryTime",value="故障恢复时间",required=true) @RequestParam String recoveryTime,
                         @ApiParam(name="checkPerson",value="检查人",required=true) @RequestParam String checkPerson) {
        SjqFlocculationProduceFault record = new SjqFlocculationProduceFault();
        record.setId(id);
        record.setEquipmentname(equipmentname);
        record.setDowntime(downtime);
        record.setOperatePerson(operatePerson);
        record.setFaultDescription(faultDescription);
        record.setStartTime(startTime);
        record.setEndTime(endTime);
        record.setPersonincharge(personincharge);
        record.setRepairPerson(repairPerson);
        record.setFaultAnalysis(faultAnalysis);
        record.setRepairMethod(repairMethod);
        record.setMethodPerson(methodPerson);
        record.setRecoveryTime(recoveryTime);
        record.setCheckPerson(checkPerson);
        return ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqFlocculationProduceFaultService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
